package com.xyz.study.design_mode.k_composite.mode;

import java.util.ArrayList;
import java.util.List;

/**
 * 角色：Composite 复合物
 * @author XYZ
 * @version 1.0.0
 * @since 2021-01-27 18:35
 */
public class Directory extends Entry{
    private String name;

    private List<Entry> entryList = new ArrayList<>();

    public Directory(String name) {
        this.name = name;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public int getSize() {
        int size = 0;
        for (Entry entry : entryList){
            size = size + entry.getSize();
        }
        return size;
    }


    @Override
    public void add(Entry entry){
        entryList.add(entry);
    }
}
